<template>
  <div class="record-browse-detail-table">
    <tag-content-header refresh setting @toolFun="toolFun" :settingData="columns"> </tag-content-header>
    <tag-table
      ref="table"
      @refresh="getList"
      :data="dataList"
      :loading="loading"
      :columns="columns"
      :params="params"
      :total="totalSize"
    >
      <template #openPage="{ scope }">
        <span>{{ setUrl(scope.row.openPage) }}</span>
      </template>
    </tag-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataList: [],
      loading: false,
      columns: [
        {
          show: true,
          label: '排名',
          prop: 'sequence',
          align: 'center',
          width: 100
        },
        {
          show: true,
          label: '受访页面',
          prop: 'openPage'
        },
        {
          show: true,
          label: '浏览量(PV)',
          prop: 'visitNum',
          align: 'center'
        },
        {
          show: true,
          label: '占比',
          prop: 'proportion',
          align: 'center'
        }
      ],
      params: {
        ascs: [],
        descs: [],
        currentPageNum: 1,
        pageSize: 10,
        queryParams: {},
        descPriority: false
      },
      totalSize: 0,
      startDate: '',
      endDate: ''
    }
  },
  methods: {
    getTable(data) {
      this.startDate = data.startDate
      this.endDate = data.endDate
      this.params.currentPageNum = 1
      this.getList(true)
    },
    getList(bool) {
      if (!bool) this.$emit('refresh')
      this.loading = true
      this.$ajax({
        url: this.$ajax.setUrl('sys/sysOperateRecord/visitPage'),
        method: 'get',
        params: this.$ajax.setParams(this.getParams())
      }).then(({ data }) => {
        if (data && data.code === '0') {
          if (data.data.currentPageNum === this.params.currentPageNum) {
            this.dataList = data.data.records
            this.totalSize = data.data.totalSize
          }
        } else {
          this.$message.error(data.data || data.msg)
        }
        this.loading = false
      })
    },
    getParams() {
      let params = {
        startDate: this.startDate,
        endDate: this.endDate,
        ascs: this.params.ascs,
        descs: this.params.descs,
        currentPageNum: this.params.currentPageNum,
        pageSize: this.params.pageSize,
        descPriority: this.params.descPriority,
        queryParams: this.params.queryParams
      }
      return params
    },
    setUrl(url) {
      return window.location.origin + url
    },
    toolFun(operation) {
      switch (operation) {
        case 'refresh':
          // 刷新动作
          this.getList()
          break
      }
    }
  }
}
</script>

<style lang="scss"></style>
